/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-07-15
 * Time: 14:30
 */
public class Test {
    public static int[] findNumberAppearOnce(int[] arr){
        if(arr.length < 2)
            return arr;

        int[] result = new int[2];  //要返回的结果
        int res = arr[0];  //第一次对所有元素进行亦或操作结果
        for(int i=1; i<arr.length; i++) {
            res ^= arr[i];
        }
        int bitIndex = 0;
        for(int i=0; i<32; i++) {  //找出亦或结果为1的位。
            if((res>>i & 1) == 1) {
                bitIndex = i;
                break;
            }
        }
        for(int i=0; i<arr.length; i++) { //根据bitIndex为1，将元素分为两组
            if((arr[i] >> bitIndex & 1) == 1)
                result[0] ^= arr[i];   //对应位为1，亦或得到的结果
            else
                result[1] ^= arr[i];   //对应位为0，亦或得到的结果
        }

        return result;
    }
    public static void main(String[] args) {
        int[] arry = {1,3,5,7,1,7};
        int[] ret = findNumberAppearOnce(arry);
        for (int x: ret) {
            System.out.print(x+" ");
        }
    }
    public static boolean isPower(int n){

        int count = 0;
        for(int i = 1;i <= 32;i++){
            if((n >> i & 1) == 1){
                count++;
            }
        }
        if(count == 1){
            return true;
        }
        return false;
    }
    public static void main1(String[] args) {
        System.out.println(isPower(6));
    }
}
